<template>
  <!-- 授权用户 -->
  <el-dialog title="历史记录" :visible.sync="visible" width="1280px" top="5vh" append-to-body>
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="灯在线状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择" clearable size="small">
          <el-option v-for="dict in dict.type.iot_online_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="工作状态" prop="lightStatus">
        <el-select v-model="queryParams.lightStatus" placeholder="请选择" clearable size="small">
          <el-option v-for="dict in dict.type.iot_work_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="故障报警" prop="lampError">
        <el-select v-model="queryParams.lampError" placeholder="请选择" clearable size="small">
          <el-option v-for="dict in dict.type.iot_bug_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="是否定时" prop="istimer">
        <el-select v-model="queryParams.istimer" placeholder="请选择" clearable size="small">
          <el-option v-for="dict in dict.type.iot_istimer_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-table @row-click="clickRow" ref="table" :data="logList" @selection-change="handleSelectionChange" height="260px">
      <el-table-column label="灯杆序号" align="center" prop="boxNo" />
      <el-table-column label="调光等级" align="center" prop="lightAdjustLevel" />
      <el-table-column label="电流" align="center" prop="lightCurrent" />
      <el-table-column label="电压" align="center" prop="lightVolt" />
      <el-table-column label="功率" align="center" prop="activePower" />
      <el-table-column label="信号强度" align="center" prop="signalt" />
      <el-table-column label="灯在线状态" align="center" width="86">
        <template slot-scope="scope">
          <div class="status-container">
            <img :src="getStateImags(scope.row.state)" alt="灯在线状态" style="width: 22px; height: 22px;"/>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="工作状态" align="center">
        <template slot-scope="scope">
          <div class="status-container">
            <img :src="getStatusImage(scope.row.lightStatus)" alt="工作状态" style="width: 22px; height: 22px;"/>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="故障报警" align="center">
        <template slot-scope="scope">
          <div class="status-container">
            <img :src="getLampErrorImage(scope.row.lampError)" alt="故障报警" style="width: 33px; height: 33px;"/>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="istimer" label="是否定时" align="center" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.iot_istimer_type" :value="scope.row.istimer"/>
        </template>
      </el-table-column>
      <el-table-column label="上报时间" align="center" prop="createTime" width="153">
        <template slot-scope="scope">{{scope.row.createTime}}</template>
      </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <!-- <el-button type="primary" @click="handleSelectUser">确 定</el-button> -->
      <el-button @click="visible = false">关 闭</el-button>
    </div>
  </el-dialog>
</template>
<script>
import {listHistory} from '@/api/iot/hgbox'
//import { unallocatedUserList, authUserSelectAll } from "@/api/system/role";
export default {
  dicts: ['iot_istimer_type','iot_online_status','iot_work_status','iot_bug_status'],
  /* props: {
    // 角色编号
    roleId: {
      type: [Number, String]
    }
  }, */
  data() {
    return {
      // 遮罩层
      visible: false,
      // 选中数组值
      userIds: [],
      // 总条数
      total: 0,
      // 未授权用户数据
      logList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        boxNo: null,
        state: null,
        lightStatus: null,
        istimer: null,
        lampError: null
      }
    };
  },
  methods: {
    // 显示弹框
    show(boxNo) {
      //alert(boxNo)
      this.queryParams.boxNo = boxNo;
      this.getList();
      this.visible = true;
    },
    getStateImags(status) {
      return status==='1'?require('@/assets/bigScreen/img/wifion.png'):require('@/assets/bigScreen/img/wifi.png');
    },
    getStatusImage(status) {// 确保比较的是字符串类型
      return status==='1'?require('@/assets/bigScreen/img/light_on.png'):require('@/assets/bigScreen/img/light_off.png');
    },
    getLampErrorImage(status) {// 确保比较的是字符串类型
      return status==='0'?require('@/assets/bigScreen/img/wx1.png'):require('@/assets/bigScreen/img/zc1.png');
    },
    clickRow(row) {
      this.$refs.table.toggleRowSelection(row);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.userIds = selection.map(item => item.userId);
    },
    // 查询表数据
    getList() {
      listHistory(this.queryParams).then(res => {
        this.logList = res.rows;
        this.total = res.total;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 选择授权用户操作 */
    handleSelectUser() {
      const roleId = this.queryParams.roleId;
      const userIds = this.userIds.join(",");
      if (userIds == "") {
        this.$modal.msgError("请选择要分配的用户");
        return;
      }
      authUserSelectAll({ roleId: roleId, userIds: userIds }).then(res => {
        this.$modal.msgSuccess(res.msg);
        if (res.code === 200) {
          this.visible = false;
          this.$emit("ok");
        }
      });
    }
  }
};
</script>
